package com.jlg.managers;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.jlg.beans.groupon.GrouponBean;
import com.julewa.db.DB;
import com.julewa.db.Identifier;
/**
*
* author: huazhang
* since : 2011-3-15
*/
@Component
@SuppressWarnings("unchecked")
public class GrouponManager
{
    private @Autowired
    DB db;
    private @Autowired
    Identifier idsrv;

    public long save(GrouponBean om)
    {
        long id = idsrv.generate("groupon");
        om.setId(id);
        boolean bool = db.insert("groupon.insert", om);
        if (bool)
        {
            return id;
        } else
        {
            return -1;
        }
    }
    
    public boolean update(GrouponBean om)
    {
        return db.update("groupon.update", om);
    }

    public List<GrouponBean> getAll()
    {
        return db.getList("groupon.all", null);
    }

    public GrouponBean findByLocationId(long locationId)
    {
        Object obj = db.getObject("groupon.findByLocationId", locationId);
        if (obj != null)
        {
            return (GrouponBean) obj;
        }
        return null;
    }
    
    public GrouponBean findByUrl(String url)
    {
        Object obj = db.getObject("groupon.findByUrl", url);
        if (obj != null)
        {
            return (GrouponBean) obj;
        }
        return null;
    }

}
